\documentclass[a4paper, 12pt]{article}

\usepackage[margin=1.5cm]{geometry}
\usepackage{listings}
\usepackage[colorlinks]{hyperref}
\usepackage{tocloft}

\setlength{\parskip}{1.5ex}
\setlength{\cftbeforesecskip}{0.5ex}

\lstset{
    frame=single, aboveskip=0.5cm, belowskip=0.2cm, basicstyle=\ttfamily,
    columns=flexible, framesep=0pt, framextopmargin=3pt,
    framexbottommargin=3pt, framexleftmargin=-1pt
}

\title{My Openbox Environment Construction}
\author{Chen Rushan\\chenrsster@gmail.com}
\date{2009.08.04 16:42}

\begin{document}

\maketitle

\begingroup
\hypersetup{linkcolor=blue}
\tableofcontents
\endgroup
\newpage

\section{Programs Used}

My daily Linux life involves using the following applications:

\begin{itemize}
    \item X server
        \begin{itemize}
            \item Xorg
        \end{itemize}
    \item window manager
        \begin{itemize}
            \item openbox package
        \end{itemize}
    \item console-related apps
        \begin{itemize}
            \item urxvt
            \item moc (console music player)
            \item irssi (irc client) / weechat
            \item vim
            \item feh (besides being used to view image, it can also be used 
                to set wallpaper)
            \item mplayer
            \item wmctrl (used to control window behavior)
        \end{itemize}
    \item X apps
        \begin{itemize}
            \item lxpanel
            \item lxappearance (to configure gtk theme)
            \item firefox (with vimperator add-on)
            \item thunderbird
            \item stardict
            \item xpdf
            \item k3b
            \item vuze
            \item ibus
            \item gmrun (a small dialog window used to run program by
                providing it command)
        \end{itemize}
    \item dev tools
        \begin{itemize}
            \item gcc
            \item gdb/cgdb
            \item make
            \item perl
            \item texlive (for LaTeX)
        \end{itemize}
    \end{itemize}
    
\section{General Issues When Decorating Desktop Environment}
    
    \subsection{Change gtk themes under openbox environment}

        \begin{enumerate}
            \item First you need to install the theme you want.

                Generally, the theme you download is an archive like a {\em
                .tar.gz file}, just extract this file into {\em
                \$HOME/.themes} to install it.

            \item Then use \textbf{lxappearance} to change to that theme.
        \end{enumerate}

    \subsection{Make urxvt as if it's part of the desktop}
    
        It's cool to make some urxvt windows as if they were part of the
        desktop, with some of them running \texttt{weechat}, and some of them
        \texttt{mocp}. My solution to provide such an illusion basically
        involves the following aspects: (Here I suppose you only want to make
        one urxvt window to be on desktop)
    
        \begin{enumerate}
            \item Give this special urxvt instance a different name so that we
                can this special one through {\em \$HOME/.Xdefaults} without
                affecting other urxvt instances. This can be easily done by
                running command like:

                \begin{lstlisting}[gobble=15]
                urxvt -name "play_urxvt"
                \end{lstlisting}
    
            \item Configure it to be fancy. This generally involves
                configuring the following properties in 
                \\{\em \$HOME/.Xdefaults}:

                \begin{lstlisting}[gobble=15]
                play_urxvt.transparent: True
                play_urxvt.shading: <num>
                play_urxvt.geometry: <width>x<height>
                play_urxvt.scrollBar: False
                play_urxvt.font: xft:Terminus-9
                play_urxvt.foreground: white
                \end{lstlisting}
    
                Besides that, I also change its shell prompt to be different
                from my general urxvt by creating a new bash startup script
                containing the following content:

                \begin{lstlisting}[gobble=15]
                if [ -f $HOME/.bashrc ]; then
                        . $HOME/.bashrc
                fi
                
                export PS1="\[\e[30;1m\][\u@\w]\$ \[\e[0m\]"
                \end{lstlisting}

                And from now on, invoke this urxvt instance by running the
                following command:

                \begin{lstlisting}[gobble=15]
                urxvt -name play_urxvt -e bash --init-file /path/to/above/bash/script
                \end{lstlisting}
    
            \item Configure openbox to tell it how to treat this urxvt
                instance. This requires modifying
                \\{\em \$HOME/.config/openbox/rc.xml} by adding the following
                configuration:

                \begin{lstlisting}[gobble=15]
                <application name="play_urxvt">
                <decor>no</decor>
                <position>
                    <x>SomeX</x>
                    <y>SomeY</y>
                </position>
                <layer>below</layer>
                <desktop>all</desktop>
                <skip_taskbar>yes</skip_taskbar>
                <skip_pager>yes</skip_pager>
                </application>
                \end{lstlisting}
    
            \item The final step is to bind a keyboard shortcut so that we can
                jump to that desktop urxvt easily, since such desktop urxvt
                has its \verb=layer= property set to be \verb=below=, to give
                it focus, we must first minimize all non-desktop applications,
                now you may already find that the function of this keyboard
                shortcut is very much like the \verb=show desktop= function
                normally found in desktop environments like Gnome. But simply
                minimizing all those applications is not enough, since even
                after that, the focus is still not on that urxvt because of
                its \verb=below layer=, but on desktop instead, so to finally
                give it focus, we need to explicitly do so by running command
                like \verb=wmctrl=.
    
                So the function that this shortcut needs to perform are:

                \begin{enumerate}
                    \item Minimize all non-desktop applications
                    \item Give focus to the desktop urxvt
                \end{enumerate}
    
                I choose to use \verb=Perl= in combination with tool
                \verb=wmctrl= to accomplish this job. The pseudo code for this
                is:

                \begin{lstlisting}[gobble=15]
                my @all_wins = `wmctrl -lG`;
                my $focus_ID;
                
                for (@all_wins) {
                        my $this_win_id;
                        set $this_win_id;
                        if (this win is not that desktop urxvt) {
                                `wmctrl -i -r $this_win_id -b add,hidden`;
                        } else {
                                $focus_ID = $this_win_id;
                        }
                }
                
                `wmctrl -i -a $focus_ID`;
                \end{lstlisting}
    
                And finally, bind this executable to a shortcut say
                \verb=A-F2= by adding the following to\\
                {\em \$HOME/.config/openbox/rc.xml}:

                \begin{lstlisting}[gobble=15]
                <keybind key="A-F1">
                <action name="execute">
                    <execute>
                    [Add this above script name here]
                    </execute>
                </action>
                </keybind>
                \end{lstlisting}
        \end{enumerate}

    The above only show you how to make one urxvt window on desktop, if there
    are more that one such windows, the whole configuration is almost the
    same, just give each of such windows a different name, configure each of
    them in {\em \$HOME/.Xdefaults}, configure openbox to treat each
    differently, and finally bind different shortcuts to each. The final step
    deserves special attention, since now you have multiple such windows, you
    need a way to distinguish between them, unfortunately, \verb=wmctrl= is
    unable to get the name of a give program, so some other feature of these
    windows is needed, and we can't use the title of the window, since title
    changes constantly, I choose their geometry. So in order to make things
    work correctly, you must choose different geometry for each different
    window, only one pixel difference is enough though.
    
    \subsection{Configure panel}

        I choose to use \verb=lxpanel=, and I think it's the best panel I've
        ever used.  The following lists all the configuration I've made:

        \begin{itemize}
            \item Make it thinner. A thin panel will make my desktop look
                clean and cool. The smallest height supported by lxpanel is 16.

            \item Add some extra panel applets:

                \begin{itemize}
                    \item CPU Usage Monitor
                    \item Battery Monitor (for my IBM laptop)
                \end{itemize}

            \item Enable the \verb=Flat Buttons= option of task bar. The
                default appearance of lxpanel's task bar is quite ugly, and at
                first I didn't find this option, which caused me to abandon
                lxpanel only after one minute or so the first time I tried to
                use it. \verb=:)= Fortunately, I found it at last, and after
                enabling this option, I think lxpanel is the one which
                satisfies me in almost all fields.
        \end{itemize}
    
    \subsection{Font issue}

        Font is a very important factor in terms of desktop appearance.
        Configuring font generally involves the following aspects:

        \begin{itemize}
            \item Terminal font. For terminal font, I prefer \verb=Terminus=
                for my two desktop urxvts, and \verb=dejavu sans mono= for my
                normal urxvt.
    
            \item CJK font. Install the following fonts for CJK characters:

                \begin{itemize}
                    \item ttf-arphic-uming
                    \item ttf-arphic-ukai
                    \item ttf-fireflysung
                \end{itemize}

                Then restart your X environment.
    
            \item Gtk application font. Gtk applications' font can easily be
                configured by using tool \verb=lxappearance=, I prefer 
                \verb=smoothansi=.
    
            \item Font properties configuration. Add the following
                configuration to you {\em \$HOME/.fonts.conf}:
                \newpage 

                \begin{lstlisting}[gobble=15]
                <match target="font" >
                <edit mode="assign" name="rgba" >
                <const>rgb</const>
                </edit>
                </match>
                <match target="font" >
                <edit mode="assign" name="hinting" >
                    <bool>true</bool>
                </edit>
                </match>
                <match target="font" >
                <edit mode="assign" name="hintstyle" >
                <const>hintfull</const>
                </edit>
                </match>
                <match target="font" >
                <edit mode="assign" name="antialias" >
                <bool>true</bool>
                </edit>
                </match>
                \end{lstlisting}
        \end{itemize}
    
    \subsection{Desktop applications geometry and position issue}

        When placing applications like urxvt as part of desktop, we generally
        need to consider the geometries and positions of them. One thing we
        need to take care is that when considering position, the \verb=X= and
        \verb=Y= you specify in {\em \$HOME/.config/openbox/rc.xml} is
        relative to the panel, that is, when you have a panel on top, (0, 0)
        will no longer mean the top-left corner of the whole screen, instead
        it means the top-left corner of the whole viewport right under the
        panel. Knowing this, here comes another issue, consider such a
        situation: You want the panel and the desktop urxvt to be
        automatically started by adding the following two lines into
        {\em \$HOME/.config/openbox/autostart.sh}, 

        \begin{lstlisting}[gobble=7]
        lxpanel &
        urxvt -name "play_urxvt" -e bash --init-file /path/to/init/file &
        \end{lstlisting}

        \noindent and you place the panel on top, and an desktop urxvt right
        under this panel, so you specify (0, 0) position for urxvt in
        \verb=rc.xml=. This situation sounds reasonable, but wait, what if
        your desktop urxvt start before the panel? This is possible since the
        two programs are started in the background, so it's uncertain that
        which one is ready first. And if so, Obviously, your urxvt will be put
        at the top of your whole screen, and after the panel is started too,
        it will be converted partially by the panel. I didn't find a perfect
        solution to this problem, you can't force panel to be started before
        desktop urxvt, what I do is to make the panel be the first one to be
        started, and sleep 1 sec before starting the desktop urxvt, like this:

        \begin{lstlisting}[gobble=7]
        lxpanel &
        ...
        sleep 1
        urxvt -name "play_urxvt" -e bash --init-file /path/to/init/file &
        ...
        \end{lstlisting}
    
    \subsection{Openbox menu}

        Since lxpanel already provides a menu, and I rarely use such menus, I
        just delete almost all things in {\em \$HOME/.config/openbox/menu.xml}.

\section{Config files related to my openbox}

    \begin{enumerate}
        \item {\em /home/chenrs/.xinitrc}
        \item {\em /home/chenrs/.Xdefaults}
        \item {\em /home/chenrs/.config/openbox/*}
        \item {\em /home/chenrs/.fonts.conf}
    \end{enumerate}
        
\section{Programs I may try in the future}

    \begin{itemize}
    \item xrandr (for changing screen resolution)
    \item uzbl (a browser following KISS Philosophy)
    \item cairo composite manager
    \item Graveman (a DVD/CD burner)
    \end{itemize}
    \end{document}
